                      ********* NOTES *********

*** the code below show merging operations in creating the masterfile. The clean file used for the analysis is also attached


****************** IPSOS SURVEYS ******************************
****************************************************************
****************** August/September 2014 ***************************
*****************************************************************

use "/Users/koo6/Desktop/Research/Knowledge and Accountability/IpsosKE_SPEC Q2_2014__V1.dta", clear

gen coethnics = 0
replace coethnics = 1 if Region == 1
replace coethnics = 1 if Region == 7

gen nhealth14 = 0
replace nhealth14 = 1 if GQ15_2 == 1
replace nhealth14 = . if GQ15_2 == . 

gen chealth14 = 0
replace chealth14 = 1 if GQ15_2 == 2
replace chealth14 = . if GQ15_2 == . 

gen neducation14 = 0
replace neducation14 = 1 if GQ15_1 == 1
replace neducation14 = . if GQ15_1 == . 

gen nroads14 = 0
replace nroads14 = 1 if GQ15_3 == 1
replace nroads14 = . if GQ15_3 == . 

gen nwater14 = 0
replace nwater14 = 1 if GQ15_5 == 1
replace nwater14 = . if GQ15_5 == . 

gen nelectricity14 = 0
replace nelectricity14 = 1 if GQ15_8 == 1
replace nelectricity14 = . if GQ15_8 == . 

gen female = 0
replace female = 0 if D9 == 1
replace female = 1 if D9 == 2
replace female = . if D9 == . 

drop coethnics

gen coethnics = 0
replace coethnics = 1 if D16 == 5
replace coethnics = 1 if D16 == 4

graph bar nhealth14,  over(female) over(coethnics)
graph save nhealth14, replace

****************************************************************
****************** TABLE 1 SUMMARIES ***************************
*****************************************************************

summarize nhealth14 
summarize nhealth14 if female == 0
summarize nhealth14 if female == 1

summarize neducation14
summarize neducation14 if female == 0
summarize neducation14 if female == 1

summarize nroads14
summarize nroads14 if female == 0
summarize nroads14 if female == 1

summarize nwater14
summarize nwater14 if female == 0
summarize nwater14 if female == 1

summarize nelectricity14
summarize nelectricity14 if female == 0
summarize nelectricity14 if female == 1

****************************************************************
****************** December 2018 ***************************
*****************************************************************

use "/Users/koo6/Desktop/Research/Knowledge and Accountability/IpsosKE_Ken Opalo_Omnibus December Survey 2018_Data_PA_V1.dta", clear


gen female = 0 
replace female = 1 if D13 == 2
replace female = . if D13 == .

gen over45 = 0
replace over45 = 1 if D14 > 45
replace over45 = . if D14 == . 

gen coethnics = 0
replace coethnics = 1 if D17 == 5
replace coethnics = 1 if D17 == 4

gen nhealthipsos18 = 0
replace nhealthipsos18 = 1 if GQ15_1 == 1
replace nhealthipsos18 = . if GQ15_1 == .

gen neducationipsos18 = 0
replace neducationipsos18 = 1 if GQ15_2 == 1
replace neducationipsos18 = . if GQ15_2 == .

gen nroadsipsos18 = 0
replace nroadsipsos18 = 1 if GQ15_3 == 1
replace nroadsipsos18 = . if GQ15_3 == .

gen nwateripsos18 = 0
replace nwateripsos18 = 1 if GQ15_4 == 1
replace nwateripsos18 = . if GQ15_4 == .

gen nelectricityipsos18 = 0
replace nelectricityipsos18 = 1 if GQ15_5 == 1
replace nelectricityipsos18 = . if GQ15_5 == .

graph bar nhealthipsos18, over(female) over(coethnics)
graph save nhealth18, replace

graph combine nhealth14.gph nhealth18.gph, cols(2) 
graph save nhealthgenderparty, replace
****************************************************************
****************** TABLE 1 SUMMARIES ***************************
*****************************************************************

summarize nhealthipsos18
summarize nhealthipsos18 if female == 0
summarize nhealthipsos18 if female == 1

summarize neducationipsos18 
summarize neducationipsos18 if female == 0
summarize neducationipsos18 if female == 1

summarize nroadsipsos18
summarize nroadsipsos18 if female == 0
summarize nroadsipsos18 if female == 1

summarize nwateripsos18
summarize nwateripsos18 if female == 0
summarize nwateripsos18 if female == 1

summarize nelectricityipsos18
summarize nelectricityipsos18 if female == 0
summarize nelectricityipsos18 if female == 1

****************************************************************
****************** Sauti za Wananchi Surveys *******************
*****************************************************************

use "/Users/koo6/Desktop/Research/Knowledge and Accountability/SzW.KE.Data.HH.Round1.dta", clear
 
merge 1:1 uhn using "/Users/koo6/Desktop/Research/Knowledge and Accountability/SzW.KE.Data.HH.Round13.dta"

drop _merge 

save combinedR1R13, replace

use "/Users/koo6/Desktop/Research/Knowledge and Accountability/SzW.KE.Data.HH.Baseline (R0).dta", clear

keep uhn d11 res_educlevel

 merge 1:1 uhn using "/Users/koo6/Desktop/Research/Knowledge and Accountability/combinedR1R13.dta"

drop _merge 
************************************************************************
*************** BASELINE SURVEY ***************************************
************************************************************************

gen urban = 0
replace urban = 1 if d11 == 2

gen aboveprimary = 0
replace aboveprimary = 1 if res_educlevel == 2
replace aboveprimary = 1 if res_educlevel == 3


************************************************************************
******************* ROUND 1 SURVEY ***********************************
************************************************************************
*** coethnicity with the president and deputy president 

gen coethnics = 0
replace coethnics = 1 if region == "Rift valley"
replace coethnics = 1 if region == "Central"

 
*** information about county development plan ***

gen informed = 0
replace informed = 1 if cati_gq3 == 1
replace informed = . if cati_gq3 < 0

*** actual participation ****

gen participated = 0
replace participated = 1 if cati_gq5 == 1
replace participated = . if cati_gq5 < 0

**** health responsibility -- who should be responsible ****

gen nhealth1 = 0
replace nhealth1 = 1 if cati_gq13 == 2
replace nhealth1 = . if cati_gq13 == . 

gen chealth1 = 0
replace chealth1 = 1 if cati_gq13 == 1
replace chealth1 = . if cati_gq13 == . 

**** reason for preference of government *************

gen reason_quality = 0 
replace reason_quality = 1 if cati_gq14 == 1
replace reason_quality = . if cati_gq14 == .

gen reason_access = 0 
replace reason_access = 1 if cati_gq14 == 2
replace reason_access = . if cati_gq14 == .

gen reason_cost = 0 
replace reason_cost = 1 if cati_gq14 == 3
replace reason_cost = . if cati_gq14 == .


**** have counties improved health *************

gen cimprovedhealth = 0
replace cimprovedhealth = 1 if cati_gq15 == 1 
replace cimprovedhealth = 1 if cati_gq15 == 3 

**** support for devolution *************

gen sdevolution = 0
replace sdevolution = 1 if cati_gq26 == 1
replace sdevolution = 1 if cati_gq26 == 2
replace sdevolution = . if cati_gq26 == .

************************************************************************
******************* ROUND 13 SURVEY **********************************
************************************************************************

gen over45 = 0
replace over45 = 1 if age > 45 

gen female = 0
replace female = 1 if gender == 2
replace female = . if gender == . 

gen province = 0
replace province = 1 if region == "Central"
replace province = 2 if region == "Coast"
replace province = 3 if region == "Eastern"
replace province = 4 if region == "Nairobi"
replace province = 5 if region == "North eastern"
replace province = 6 if region == "Nyanza"
replace province = 7 if region == "Rift valley"
replace province = 8 if region == "Western"


**** political approval and voting intention *************

gen disapprovegov = 0
replace disapprovegov = 1 if q7 == 4
replace disapprovegov = 1 if q7 == 5
replace disapprovegov = . if q7 == .

gen vregistered = 0
replace vregistered = 1 if q26 == 1
replace vregistered = . if q26 == . 

gen voteforgov = 0 
replace voteforgov = 1 if q28_5 == 1
replace voteforgov = . if q28_5 == .

gen kenyatta = 0
replace kenyatta = 1 if q33 == 2
replace kenyatta = . if q33 == . 

gen odinga = 0
replace odinga = 1 if q33 == 1
replace odinga = . if q33 == . 

**** functiosn of tiers of government *************

gen nhealth13 = 0
replace nhealth13 = 1 if q6_1 == 1
replace nhealth13 = . if q6_1 == . 

gen nprimaryed13 = 0
replace nprimaryed13 = 1 if q6_2 == 1
replace nprimaryed13 = . if q6_2 == . 

gen nnursery13 = 0
replace nnursery13 = 1 if q6_3 == 1
replace nnursery13 = . if q6_3 == . 

gen nroads13 = 0
replace nroads13 = 1 if q6_4 == 1
replace nroads13 = . if q6_4 == . 

gen nagriculture13 = 0
replace nagriculture13 = 1 if q6_5 == 1
replace nagriculture13 = . if q6_5 == . 

gen nwater13 = 0
replace nwater13 = 1 if q6_6 == 1
replace nwater13 = . if q6_6 == . 

gen votelikely = 0
replace votelikely = 1 if q27 == 1
replace votelikely = 1 if q27 == 2
replace votelikely = . if q27 == .

**** wealth level *************

gen assets = asset_wealth_index

************ Tables 1 and 2 ****************

summarize nhealth1
summarize nhealth1 if female == 0
summarize nhealth1 if female == 1

summarize nhealth13
summarize nhealth13 if female == 0
summarize nhealth13 if female == 1

summarize nprimaryed13
summarize nprimaryed13 if female == 0
summarize nprimaryed13 if female == 1

summarize nroads13
summarize nroads13 if female == 0
summarize nroads13 if female == 1

summarize nwater13
summarize nwater13 if female == 0
summarize nwater13 if female == 1

summarize nagriculture13
summarize nagriculture13 if female == 0
summarize nagriculture13 if female == 1

************************************************************************
hist cati_gq13, frac
graph save round1_health, replace 

graph bar nhealth1, over(female) over(kenyatta)
graph bar nhealth13, over(female) over(kenyatta)

************ generate summary statistics ****************

sutex female aboveprimary urban age over45 assets nhealth1 nhealth13 ///
 nagriculture nprimaryed nroads nwater ///
 cimprovedhealth participated ///
sdevolution vregistered votelikely disapprovegov voteforgov /// 
kenyatta, nobs minmax


********************************************************************* 
			*********** results ***************
*********************************************************************	
eststo clear 

logit nhealth1 female aboveprimary, robust
eststo

logit nhealth1 female aboveprimary age assets, robust
eststo

logit nhealth1 female aboveprimary age assets urban cimprovedhealth, robust
eststo 

logit nhealth1 female aboveprimary age assets urban cimprovedhealth sdevolution participated kenyatta, robust
eststo

esttab using results1.tex, se replace

*********************************************************************
			
eststo clear 

logit nhealth13 female aboveprimary urban, robust
eststo

logit nhealth13 female aboveprimary urban female#over45 assets sdevolution, robust
eststo

logit nhealth13 female aboveprimary urban female#kenyatta assets sdevolution, robust
eststo 

logit nhealth13 female aboveprimary urban female#over45 assets sdevolution cimprovedhealth participated kenyatta, robust
eststo

esttab using results2.tex, se replace

*********************************************************************
		********** political action ***************
*********************************************************************
eststo clear 

logit disapprove nhealth13 female age aboveprimary urban assets cimprovedhealth sdevolution, robust 
eststo

logit disapprove nhealth13 nhealth13#female age aboveprimary urban assets cimprovedhealth sdevolution kenyatta, robust 
eststo

logit voteforgov nhealth13 female age aboveprimary urban assets cimprovedhealth sdevolution, robust
eststo 

logit voteforgov nhealth13 nhealth13#female age aboveprimary urban assets cimprovedhealth sdevolution kenyatta, robust
eststo 

esttab using results3.tex, se replace

*********************************************************************
			*********** OLS results ***************
*********************************************************************	
eststo clear 

reg nhealth1 female aboveprimary, robust
eststo

reg nhealth1 female aboveprimary age assets, robust
eststo

reg nhealth1 female aboveprimary age assets urban cimprovedhealth, robust
eststo 

reg nhealth1 female aboveprimary age assets urban cimprovedhealth sdevolution participated kenyatta, robust
eststo

esttab using olsresults1.tex, se replace

*********************************************************************
			
eststo clear 

reg nhealth13 female aboveprimary urban, robust
eststo

reg nhealth13 female aboveprimary urban female#over45 assets sdevolution, robust
eststo

reg nhealth13 female aboveprimary urban female#kenyatta assets sdevolution, robust
eststo 

reg nhealth13 female aboveprimary urban female#over45 assets sdevolution cimprovedhealth participated kenyatta, robust
eststo

esttab using olsresults2.tex, se replace

*********************************************************************
		********** political action ***************
*********************************************************************
eststo clear 

reg disapprove nhealth13 female age aboveprimary urban assets cimprovedhealth sdevolution, robust 
eststo

reg disapprove nhealth13 nhealth13#female age aboveprimary urban assets cimprovedhealth sdevolution kenyatta, robust 
eststo

reg voteforgov nhealth13 female age aboveprimary urban assets cimprovedhealth sdevolution, robust
eststo 

reg voteforgov nhealth13 nhealth13#female age aboveprimary urban assets cimprovedhealth sdevolution kenyatta, robust
eststo 

esttab using olsresults3.tex, se replace

*********************************************************************
**** Merge files from Round 1 and Round 13 *********************
*********************************************************************

use "/Users/koo6/Desktop/Knowledge and Accountability/SzW.KE.Data.HH.Round1.dta", clear
 
merge 1:1 uhn using "/Users/koo6/Desktop/Knowledge and Accountability/SzW.KE.Data.HH.Round13.dta"

*********************************************************************
*** Display distribution of knowledge by age group and gender **** 
*********************************************************************

collapse (mean) mhealth = nhealth1 (sem) sehealth = nhealth1 n = nhealth1, by(over45 female)
 drop if female == .
 
 gen agegroup = 1
 replace agegroup = 2 if female == 0 & over45 == 1 
 replace agegroup = 3 if female == 1 & over45 == 0
 replace agegroup = 4 if female == 1 & over45 == 1
 
 label define agegroup 1 "M 45 & Under" 2 "M over 45" 3 "W 45 and Under" 4 "W over 45"
 serrbar mhealth sehealth agegroup, scale(1.96) ylab(0 (0.1) 0.6) xlab (1(1)4) xlabel (,valuelabel)

 
 collapse (mean) mhealth = nhealth13 (sem) sehealth = nhealth13 n = nhealth13, by(over45 female)
 drop if female == .
 
 gen agegroup = 1
 replace agegroup = 2 if female == 0 & over45 == 1 
 replace agegroup = 3 if female == 1 & over45 == 0
 replace agegroup = 4 if female == 1 & over45 == 1
 
 label define agegroup 1 "M 45 & Under" 2 "M over 45" 3 "W 45 and Under" 4 "W over 45"
 serrbar mhealth sehealth agegroup, scale(1.96) ylab(0 (0.1) 0.6) xlab (1(1)4) xlabel (,valuelabel)
 

